package cc.lcdsg.interceptor;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class IndexInterceptor extends HandlerInterceptorAdapter{
	
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		System.out.println("=================拦截器，controller代码执行前");
		Enumeration<String> s = request.getParameterNames();
		StringBuffer sb = new StringBuffer();
		while(s.hasMoreElements()) {
			sb.append(s.nextElement() + ",");
		}
		System.out.println("参数有:" + sb);
		return true;
	}
	
	@Override
	public void postHandle(
			HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
			throws Exception {
		System.out.println("==================拦截器，生成响应后");
		request.setAttribute("name", "响应后参数");
	}
	
	@Override
	public void afterCompletion(
			HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("=================拦截器，页面渲染成功");
	}
}
